package com.zzsy.carosshopprojects.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.king.base.adapter.ViewHolderRecyclerAdapter;
import com.king.base.adapter.holder.ViewHolder;
import com.yatoooon.screenadaptation.ScreenAdapterTools;
import com.zzsy.carosshopprojects.R;
import com.zzsy.carosshopprojects.bean.GetMainCardBean;
import com.zzsy.carosshopprojects.util.ConverterHelper;
import com.zzsy.carosshopprojects.util.StringUtils;

import java.math.BigDecimal;
import java.util.List;

public class FuCardListAdapter extends ViewHolderRecyclerAdapter<GetMainCardBean.MyGrantSubCardsBean> {

    public FuCardListAdapter(Context context, List<GetMainCardBean.MyGrantSubCardsBean> listData, int layoutId) {
        super(context, listData, layoutId);
    }

    @Override
    public View buildConvertView(LayoutInflater layoutInflater, ViewGroup parent, int viewType) {
        View view = layoutInflater.inflate(R.layout.adapter_fucardlist, null);
        ScreenAdapterTools.getInstance().loadView(view);
        return view;
    }

    @Override
    public void bindViewDatas(ViewHolder helper, GetMainCardBean.MyGrantSubCardsBean cardFuBean, int positions) {
        String cardName = cardFuBean.getRealName();
        String cardPhone = cardFuBean.getPhone();
        String cardSAmount = cardFuBean.getUseLimit();
        String cardZongAmount = cardFuBean.getPayLimit();
        String currentStatus = cardFuBean.getCurrentStatus();
        String subCardType = cardFuBean.getSubCardType();
        TextView tvGuashi=helper.getView(R.id.tv_guashi);
        int img;
        String type = "";
        if (!StringUtils.isEmpty(subCardType)) {
            if ("1".equals(subCardType)) {
                img = R.mipmap.mother_card;
                type = "父母卡";
            } else if ("3".equals(subCardType)) {
                img = R.mipmap.qingqing_card;
                type = "伴侣卡";
            } else if ("2".equals(subCardType)) {
                img = R.mipmap.son_card;
                type = "子女卡";
            } else if ("4".equals(subCardType)) {
                img = R.mipmap.yuangong_card;
                type = "企业卡";
            } else {
                img = R.mipmap.other_card;
                type = "其他卡";
            }
            helper.setImageResource(R.id.img_card, img);
            helper.setText(R.id.tv_card_type, type);
        }
        if (!StringUtils.isEmpty(currentStatus)) {
            if ("2".equals(currentStatus)) {
              tvGuashi.setVisibility(View.VISIBLE);
            } else {
              tvGuashi.setVisibility(View.GONE);
            }
        }
        //设置数据
        helper.setText(R.id.tv_name,cardName);
        helper.setText(R.id.tv_phone,"电话" + cardPhone);
        helper.setText(R.id.tv_sy_amount,"已用￥" + ConverterHelper.toBigDecimal(cardSAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
        String zAmount = ConverterHelper.toBigDecimal(cardZongAmount).divide(ConverterHelper.toBigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
        helper.setText(R.id.tv_zong_amount,"￥" + zAmount);
    }
}
